//
//  LabelAndCollectionViewCollectionReusableView.m
//  14collection练习
//
//  Created by dllo on 16/8/2.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LabelAndCollectionViewCollectionReusableView.h"

@interface LabelAndCollectionViewCollectionReusableView ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic,strong) UILabel *label;
@property (nonatomic,strong) UICollectionView *collection;
@end

@implementation LabelAndCollectionViewCollectionReusableView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 50)];
        _label.text = @"分类";
        [self addSubview:_label];
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        CGFloat height = (frame.size.height - 90) / 3;
        layout.minimumInteritemSpacing = 5;
        layout.minimumLineSpacing = 5;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _collection.backgroundColor = [UIColor whiteColor];
        layout.itemSize = CGSizeMake((frame.size.width - 30) / 2, height);
        _collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, frame.size.width, frame.size.height - 50) collectionViewLayout:layout];
        _collection.delegate = self;
        _collection.dataSource = self;
        [self addSubview:_collection];
        _collection.pagingEnabled = YES;
        
        [_collection registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell1"];
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 20;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell1 = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
    cell1.backgroundColor = [UIColor redColor];
    return cell1;
}


@end
